package com.msh.starter.common.web.api;


import com.msh.frame.client.common.Result;
import com.msh.frame.client.interfaces.IClassLoadLog;
import com.msh.frame.interfaces.IClearCache;
import javax.annotation.Resource;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "清理缓存-api相关接口")
@Slf4j
@RestController
@RequestMapping("/api/clearCache")
@ConditionalOnProperty(name = "msh.starter.web.api.clear-cache.enable", havingValue = "true")
public class ClearCacheApi implements IClassLoadLog {
  @Resource
  private IClearCache clearCache;

  @Operation(summary = "清理缓存")
  @GetMapping("clear")
  public Result clear(@RequestParam("cache") String cache) {
    clearCache.clear(cache);
    return Result.successReturn();
  }

  @Override
  public String logInfo() {
    return new StringBuilder()
        .append("----执行类 ")
        .append(ClearCacheApi.class)
        .append("\r\n")
        .append("--------加载类 ")
        .append(ClearCacheApi.class)
        .append("\r\n")
        .toString();
  }
}
